package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 查重对象枚举
 *
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/31 16:11
 * @since v1.0
 */
@Getter
public enum CheckRepeatObjEnum {
    /**
     * 查重对象
     * 1：电话查重
     * 2：客户姓名查重
     * 3：合同名称查重
     * 4：bom版本查重
     */
    PHONE(1, "phone", "enum.checkRepeatObj.alias.phone"),
    CUSTOMER_NAME(2, "customerName", "enum.checkRepeatObj.alias.customer_name"),
    CONTRACT_NAME(3, "contractName", "enum.checkRepeatObj.alias.contract_name"),
    FINISHED_PRODUCT_VERSION(4, "finishedProductVersion", "enum.checkRepeatObj.alias.finished_product_version"),
    ;
    private Integer code;

    private String type;

    private String alias;

    CheckRepeatObjEnum(Integer code, String type, String alias) {
        this.code = code;
        this.type = type;
        this.alias = alias;
    }

    public static CheckRepeatObjEnum getByCode(Integer code) {
        for (CheckRepeatObjEnum checkRepeatObjEnum : values()) {
            if (Objects.equals(checkRepeatObjEnum.getCode(), code)) {
                return checkRepeatObjEnum;
            }
        }
        return null;
    }

    public String getAlias() {
        return I18nMessageUtil.getMessage(alias);
    }

}
